package org.example;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;

public class PokerGame {
    static HashMap<Integer,String> map=new HashMap<>();
    static ArrayList<Integer> list = new ArrayList<>();
    static{
        String[] color={"♠","♥","♦","♣"};
        String[] number={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
        int serialNumber=1;
            for (String n : number) {
                for (String c : color) {
                    map.put(serialNumber,c+n);
                    list.add(serialNumber);
                    serialNumber++;
                }
            }
            map.put(serialNumber,"小王");
            list.add(serialNumber);
            serialNumber++;
            map.put(serialNumber,"大王");
            list.add(serialNumber);
    }
    public PokerGame() {
        //洗牌
        Collections.shuffle(list);
        //发牌
        TreeSet<Integer> lord=new TreeSet<>();
        TreeSet<Integer> player1=new  TreeSet<>();
        TreeSet<Integer> player2=new  TreeSet<>();
        TreeSet<Integer> player3=new  TreeSet<>();

        for (int i = 0; i < list.size(); i++) {
            int serialNumber=list.get(i);
            if(i<=2){
                lord.add(serialNumber);
            }else if(i%3==0){
                player1.add(serialNumber);
            }else if(i%3==1){
                player2.add(serialNumber);
            }else{
                player3.add(serialNumber);
            }
        }
        //查看牌
        lookPoker("底牌",lord);
        lookPoker("玩家1",player1);
        lookPoker("玩家2",player2);
        lookPoker("玩家3",player3);


    }
    public void lookPoker(String name, TreeSet<Integer> list){
        System.out.println(name+"的牌为：");
        for (Integer serialNumber : list) {
            //map.get(serialNumber)得到的是键值夜就是牌值
            String poKer=map.get(serialNumber);
            System.out.print(poKer+" ");
        }
        System.out.println();
    }
}
